<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 将字符串中的SM替换成**
        var str = 'asdasdSMasdasdasdSMsdasdasdSMsadasd'
        var res=str.replace('SM','**')
        console.log(res);
        //不知道字符串中有多少个SM，通过循环找出
        while (res.indexOf('SM')!==-1){
            res=res.replace('SM','**')
        }
        console.log(res);
    </script>
</body>
</html>